package com.harmontronics.hanma.paas.paas.controller;

import com.harmontronics.hanma.paas.paas.domain.iam.entity.UserGroupRoleList;
import java.util.Arrays;
import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.harmontronics.hanma.paas.paas.common.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.harmontronics.hanma.paas.paas.service.HmUserGroupRoleAppService;
import com.harmontronics.hanma.paas.paas.dto.iam.input.HmUserGroupRoleCreateInput;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.HmUserGroupRole;


/**
 * 用户组角色表
 *
 * @author paas-generator
 * @email paas-generator@harmontronics.com
 * @date 2021-04-07 10:35:20
 */
@RestController
@RequestMapping("/api/hmusergrouprole")
@Api(tags = {"用户组角色表"})
public class HmUserGroupRoleController {
    @Autowired
    private HmUserGroupRoleAppService hmUserGroupRoleappService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("获取所有用户组角色")
    public ResponseEntity<List<UserGroupRoleList>> list(@RequestParam Long groupId) {
        List<UserGroupRoleList> hmUserGroupRoleList = hmUserGroupRoleappService.selectGroupRole(groupId);
        return ResponseEntity.ok(hmUserGroupRoleList);
    }

    @PostMapping
    @ApiOperation(value = "创建用户组角色")
    public ResponseEntity create(@RequestBody HmUserGroupRoleCreateInput userGroupRoleCreate) {
        HmUserGroupRole hmUserGroupRole = BeanUtil.toBean(userGroupRoleCreate,HmUserGroupRole.class);
        hmUserGroupRoleappService.create(hmUserGroupRole);
        return ResponseEntity.ok();
    }


    /**
     * 删除
     */
    @DeleteMapping()
    @ApiOperation("删除")
    public ResponseEntity<String> delete(@RequestBody Long[] ids) {
        hmUserGroupRoleappService.remove(Arrays.asList(ids));
        return ResponseEntity.ok();
    }

}
